<?php
/**
 * EntryPointsView.php
 * 
 * @category   Naneau
 * @package    Naneau_Plugin
 * @copyright  Copyright (c) 2007 Maurice Fonk - http://naneau.nl
 * @version    0.1.1
 */

/** base class */
require_once 'Zend/Controller/Plugin/Abstract.php';

/**
 * Naneau_Controller_Plugin_EntryPointsView
 * 
 * a simple plugin to set a scheme for view scripts, based on certain front
 * controller params, to be used in conjunction with Naneau_Controller_Plugin_EntryPoints
 *
 * @category   Naneau
 * @package    Naneau_Plugin
 * @copyright  Copyright (c) 2007 Maurice Fonk - http://naneau.nl
 */
class Naneau_Controller_Plugin_EntryPointsView extends Zend_Controller_Plugin_Abstract {

    /**
     * params to look for
     *
     * @var array
     */
    private $_params = array();

    /**
     * constructor
     *
     * @param array $params front controller params to prepend to the VR spec
     */
    public function __construct(array $params = array()) {
        $this->_params = $params;
    }

    public function dispatchLoopStartup() {
        $viewRenderer = Zend_Controller_Action_HelperBroker::getExistingHelper('viewRenderer');
        //the view renderer

        $spec = '';
        //start with empty spec
        if (count($this->_params) > 0) {
            //we have params to check, yay!
            foreach ($this->_params as $param) {
                //for each of those params
                $value = $this->getRequest()->getParam($param);
                //get it's value from the front controller
                if ($value !== null) {
                    //there IS a value
                    $spec .= $value . '/';
                    //add to the spec
                }
            }
        }
        //add param values to spec

        $spec = $viewRenderer->getViewBasePathSpec() . '/' . $spec;
        //add the original spec
        
        $viewRenderer->setViewBasePathSpec($spec);
        //set it in viewRenderer
    }
}